
function gmcp(){
	loadViewDialog('收款', 'buyProduct?ymtype=1&cusIds=' + $("#customerIds").val(),null,1100,600);
}
//获取顾客信息
	function searchCus(){
		var tsv= '温馨提示：';
		
		
		 $("#toStoretablediv").css("border","");
		 $("#mintablediv").css("border","");
		 $('#dengjitz').panel('close');
		 $('#khxxpanel').panel('close');
		 $("#zfzdts").html('').hide();
		 $("#cltz").show();
		 $("#gxxxcx").show();
		 $('#toStorebd1').html('' );
		 $('#toStorebd2').html('' );
		 $('#toStorebd3').html('' );
		 $('#minbd1').html('' );
		 $('#minbd2').html('' );
		 $('#minbd3').html('' );
		 $('#nowweight').html('' );
		 $("#mbtablediv").html("");
		 $('#fieldsetdiv').addClass("fieldsetdivys1");
		 $('#legenddiv').html("");
		 
		var hybh=$('#customerHybh').val();
		var name=$('#customerName').val();
		var phone=$('#customerPhone').val();
		
		if(hybh==''&&name==''&&phone==''){
			return false;
		}
		
		var url='/bentryRegister/getCusByHybh';
		var data={"hybh":hybh,"name":name,"phone":phone};
		var reData = common_ajax.ajaxFunc(url,data,"json");
		if(reData.msg==200){
			
			$("#customerIds").val(reData.customer.ids);
			$("#customerName").textbox('setValue',reData.customer.name);
			$("#customerPhone").textbox('setValue',reData.customer.phone);
			$("#customerHybh").textbox('setValue',reData.customer.hybh);
			
			
			

			var customerIds=reData.customer.ids;
			
			//获取是否支付疗程款，单疗程次数，测量尺寸日期
			var url='/binShopService/getInshopInfo';
			var data={"customerIds":customerIds}
			var resultMap = common_ajax.ajaxFunc(url,data,"json");
			if(resultMap.dlcnum !=null && resultMap.dlcnum != ""){
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">亲，您购买了单疗程哦，单疗程剩余'+resultMap.dlcnum+'次！</span>';
				$("#zfzdts").html('温馨提示：<span   style=" color: black;margin-left: 55px">亲，您购买了单疗程哦，单疗程剩余'+resultMap.dlcnum+'次！</span>').show();
			}
			if( resultMap.yearflag == "0"){
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">'+resultMap.yearms+'</span>';
				$("#zfzdts").html('温馨提示：<span   style=" color: black;margin-left: 55px">'+resultMap.yearms+'</span>').show();
				//return false;
			}
			if( resultMap.weightflag == "0"){
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">'+resultMap.weightms+'</span>';
				$("#zfzdts").html('温馨提示：<span   style=" color: black;margin-left: 55px">'+resultMap.weightms+'</span>').show();
				
			}
			if( resultMap.qkjeflag == "0"){
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">'+resultMap.qkjems+'</span>';
				$("#zfzdts").html('温馨提示：<span   style=" color: black;margin-left: 55px">'+resultMap.qkjems+'</span>').show();
				
			}

			if( resultMap.msg != null){
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">'+resultMap.msg+'</span>';
				tsv += '<span   style="width:80px;color: red;"  onclick="gmcp()">点击购买</span>';
			}
			
			
			if( resultMap.zcs != null){
				$('#zcscount').val(resultMap.zcscount);
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">'+resultMap.zcs+'</span>';
			}
			
			if(resultMap.dlcnum <= 0){
				 parent.$.messager.confirm('Confirm','单疗程剩余次数为0，确定继续服务？',function(r){
						if (r){
							
						}else{
							window.location.reload();
						}
					});
			}
			
			if(resultMap.dlcjs == "0"){
				 parent.$.messager.confirm('Confirm','当前顾客为单疗程已减10斤，确定继续服务？',function(r){
						if (r){
							
						}else{
							window.location.reload();
						}
					});
			}
			
			var days = reData.days;
			var daysflag = reData.daysflag;
			if(daysflag==1){
				if(days==-1){
					chicun(days);
				}else if(days>0){
					chicun(days);
				}
			}
			
			
			
			if(reData.customerDetail.customertype=='1'){
				$('#dengjitz').panel('open'); 
				$("#cltz").hide();
				$('#khxxpanel').panel('close'); 
				tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">亲，我只塑性不减肥哦！</span>';
			}else{
				$('#dengjitz').panel('open'); 
				$('#khxxpanel').panel('open');
				
			
			
			var jlbtjs = (parseFloat(reData.customerDetail.nowweight)-parseFloat(reData.customerDetail.standardweight)).toFixed(1);
			$('#jlbtjs').html(jlbtjs+"斤");
			if(jlbtjs<0){
				$('#jlbtjs').html("巩固顾客");
			}
			
			
			
			$('#customertype').val(reData.customerDetail.customertype);
			$('#standardweight').val(reData.customerDetail.standardweight);
			$('#minWeightinput').val(reData.customerDetail.minweight);
			$('#nowWeightinput').val(reData.customerDetail.nowweight);
			$('#minWeight').html('最低<br/>（日期：'+reData.customerDetail.mindate+'，体重：'+ reData.customerDetail.minweight+'斤）');
			$('#nowWeight').html('上次<br/>（日期：'+reData.customerDetail.tostoredate+'，体重：'+reData.customerDetail.nowweight+'斤）');
			$('#minbd').html("");
			$('#toStorebd').html("");	
			
			
			//alert(resultMap.mbRecord);
			//alert(JSON.stringify(resultMap.mbRecord));
			
			if(resultMap.mbRecord!=null){
				
				var table ='<table id="mbtable" border="1"  bordercolor="#DDDDDD" style="width:100%;height:85%; text-align: center;font-size: 15px;">'
							+'<tr style="width:100%;height: 40px;font-weight: bold;">'
							+'<td >目标名称</td>'
							+'<td >开始时间</td>'
							+'<td >结束时间</td>'
							+'<td >初始体重</td>'
							+'<td >目标体重</td>'
							+'<td >应减斤数</td>'
							+'<td >实减斤数</td>'
							+'<td style="width:15%;">完成率</td>'
							+'</tr>'
							+'</table>';
				$("#mbtablediv").html(table);
				$.each(resultMap.mbRecord, function(index, content){ 
					var	newRow='<tr style="width:100%;height: 40px;">'
							+'<td >'+content.targetname+'</td>'
							+'<td >'+content.starttime+'</td>'
							+'<td >'+content.endtime+'</td>'
							+'<td >'+content.startwei+'</td>'
							+'<td >'+content.targetwei+'</td>'
							+'<td >'+content.del+'</td>'
							+'<td >'+content.sjweight+'</td>'
							+'<td >'+content.bfb+'%</td>'
							+'</tr>';
						$('#mbtable').append(newRow); 
				  });
				
				
			}else{
				$("#mbtablediv").html("");
			}
			
			
					
					
					
			}
			
			
		}else{
			tsv += '<br/><span   style=" color: black;font-weight:normal;margin-left: 55px">'+reData.msg+'</span>';
			$("#zfzdts").html('温馨提示：<span   style=" color: black;font-weight:normal;margin-left: 55px">'+reData.msg+'</span>').show();
			$("#gxxxcx").hide();
			//$.alert(parent.$, reData.msg);
		}
		if(tsv.length>7){
			$("#zfzdts").html(tsv).show();
		}
		return  reData;
	}






	//查看顾客详细信息
	function lookCustomerInfo(){

		if($("#customerIds").val()!=null&&$("#customerIds").val()!=''){
			loadViewDialog('查看顾客详细信息', 'customerInfoStatistic/lookCustomerInfo?ids=' + $("#customerIds").val(),null,1100,600);
		}else{
			$.alert(parent.$, "请选择顾客！");

		}
	}











	function  savePart(){
	
	var customerIds=$('#customerIds').val();
	$('#cIds').val(customerIds);
	var cIds=$('#cIds').val();
	var hybh=$('#customerHybh').val();
	var name=$('#customerName').val();
	var phone=$('#customerPhone').val();
	
	if(cIds==null||cIds.length==0){
		$.alert(parent.$, "顾客信息不能为空！");
		return false
	}
	
	var posqs=$('#posqs').val();
	
	/*if(posqs==null||posqs.length==0){
		$.alert(parent.$, "脐上不能为空！");
		return false
	}*/
	
	
	var posqz=$('#posqz').val();
	/*if(posqz==null||posqz.length==0){
		$.alert(parent.$, "脐中不能为空！");
		return false
	}*/
	
	var posqx=$('#posqx').val();
	/*if(posqx==null||posqx.length==0){
		$.alert(parent.$, "脐下不能为空！");
		return false
	}*/
	
	var poszb=$('#poszb').val();
	/*if(poszb==null||poszb.length==0){
		$.alert(parent.$, "左臂不能为空！");
		return false
	}*/
	
	var posyb=$('#posyb').val();
	/*if(posyb==null||posyb.length==0){
		$.alert(parent.$, "右臂不能为空！");
		return false
	}*/
	
	
	
	var poszdt=$('#poszdt').val();
	/*if(poszdt==null||poszdt.length==0){
		$.alert(parent.$, "左大腿不能为空！");
		return false
	}*/
	
	var posydt=$('#posydt').val();
	/*if(posydt==null||posydt.length==0){
		$.alert(parent.$, "右大腿不能为空！");
		return false
	}*/
	
	
	var poszxt=$('#poszxt').val();
	/*if(poszxt==null||poszxt.length==0){
		$.alert(parent.$, "左小腿不能为空！");
		return false
	}*/
	
	var posyxt=$('#posyxt').val();
	/*if(posyxt==null||posyxt.length==0){
		$.alert(parent.$, "右小腿不能为空！");
		return false
	}*/
	
	if((posqs==null||posqs.length==0)&&(posqz==null||posqz.length==0)&&(posqx==null||posqx.length==0)&&(poszb==null||poszb.length==0)&&(posyb==null||posyb.length==0)&&(poszdt==null||poszdt.length==0)&&(posydt==null||posydt.length==0)&&(poszxt==null||poszxt.length==0)&&(posyxt==null||posyxt.length==0)){
		$.alert(parent.$, "尺寸不能全为空！");
		return false;
	}
	

	var url='/binShopService/savePart';
	//var data=$('#info_form').serialize();
	var data={'cIds':cIds,'posyxt':posyxt,'poszxt':poszxt,'posqs':posqs,'posqz':posqz,'posqx':posqx,'poszdt':poszdt,'posydt':posydt,'poszb':poszb,'posyb':posyb};
	
	var reData = common_ajax.ajaxFunc('/binShopService/savePart',data);
	if(reData == "200"){
		 $.slideMsg("保存成功", parent.$);
		 $("#posqs").textbox("clear");
		 $("#posqz").textbox("clear");
		 $("#posqx").textbox("clear");
		 $("#poszb").textbox("clear");
		 $("#posyb").textbox("clear");
		 $("#poszdt").textbox("clear");
		 $("#posydt").textbox("clear");
		 $("#poszxt").textbox("clear");
		 $("#posyxt").textbox("clear");
		 $('#size').window('close');
		
	}else{
		$.alert(parent.$, reData);
	}
	
}	
		
		
	$(document).ready(function () {
		
		var flag = $("#flag").val();
		if(flag=='1'){
			 parent.window.nodeClick("正在服务", "/beingServed");
		}
		

		$("#customerName").combobox({

		onChange: function (n,o) {

			$("#customerPhone").textbox("clear");
			$("#customerHybh").textbox("clear");
			searchCus();
		}

		});
		$("#customerPhone").combobox({

			onChange: function (n,o) {

				$("#customerName").textbox("clear");
				$("#customerHybh").textbox("clear");
				searchCus();
			}

			});
		$("#customerHybh").combobox({

			onChange: function (n,o) {

				$("#customerName").textbox("clear");
				$("#customerPhone").textbox("clear");
				searchCus();
			}

			});
		
		$("#nowweight").combobox({
			

			onChange: function (n,o) {
				$("#jlbtjs").html((parseFloat($('#nowWeightinput').val())-parseFloat($('#standardweight').val())).toFixed(1));
				
				$('#fieldsetdiv').addClass("fieldsetdivys1");
				$("#toStoretablediv1").css("border","");
				$('#legenddiv').html("")
				
				if(parseFloat(n)>70){
					var iscg = (parseFloat(n)-parseFloat($('#standardweight').val())).toFixed(1);
					if(iscg<=5){
						$("#toStoretablediv1").css("border","5px solid #00ccff");
					}
					if(iscg<=0&&$('#customertype').val()!='2'){
								$('#fieldsetdiv').removeClass("fieldsetdivys1");
								$('#fieldsetdiv').addClass("fieldsetdivys");
								$('#legenddiv').html("恭喜您，减肥成功了！");
								$("#jlbtjs").html("恭喜您，减肥成功了！");
								$("#toStoretablediv1").css("border","5px solid green");
					}else if(iscg>0&&$('#customertype').val()!='2'){
						$("#jlbtjs").html(iscg+"斤");
					}else if($('#customertype').val()=='2'){
						$("#jlbtjs").html("巩固顾客！");
					}
				}
				
				
				
				 $("#toStoretablediv").css("border","");
				 $("#mintablediv").css("border","");
				 $('#toStorebd1').html('' );
				 $('#toStorebd2').html('' );
				 $('#toStorebd3').html('' );
				 $('#minbd1').html('' );
				 $('#minbd2').html('' );
				 $('#minbd3').html('' );
				
			if(n>0){
				
				
				var nowWeight = (parseFloat($('#nowWeightinput').val())-parseFloat(n)).toFixed(1);
				var minWeight = (parseFloat($('#minWeightinput').val())-parseFloat(n)).toFixed(1);
				
				//正 掉秤
				//负 涨称
				//0 平称
				if($('#nowWeightinput').val()>0){
					//alert(nowWeight)
					if(nowWeight>0){
						 $('#toStorebd3').html(nowWeight+'斤' );
						 $("#toStoretablediv").css("border","5px solid green");
					}else if(nowWeight==0){
						 $('#toStorebd2').html(nowWeight+'斤' );
						 $("#toStoretablediv").css("border","5px solid yellow");
					}else if(nowWeight<0){
						 $('#toStorebd1').html(nowWeight*-1+'斤' );
						 $("#toStoretablediv").css("border","5px solid red");
					}
				}
				
				
				
				
				if($('#minWeightinput').val()>0){
				if(minWeight>0){
					 $('#minbd3').html(minWeight+'斤' );
					 $("#mintablediv").css("border","5px solid green");
				}else if(minWeight==0){
					 $('#minbd2').html(minWeight+'斤' );
					 $("#mintablediv").css("border","5px solid yellow");
				}else if(minWeight<0){
					 $('#minbd1').html(minWeight*-1+'斤' );
					 $("#mintablediv").css("border","5px solid red");
				}
				}
				
				
					
					
					
					
			}
				
			

			}

			});
		var hybh=$('#customerHybh').val();
		var name=$('#customerName').val();
		var phone=$('#customerPhone').val();
		
		if(hybh==''&&name==''&&phone==''){
			return false;
		}
		searchCus();
	});
	


	/*保存服务
	 * 
	 */

	function  saveInfo(){
		
		var customerIds=$('#customerIds').val();
		var nowweight=$('#nowweight').val();
		
		if(customerIds==null||customerIds.length==0){
			$.alert(parent.$, "顾客信息不能为空！");
			return false
		}
		
		
		if($('#cltz').css('display')=='inline'&&(nowweight==null||nowweight<1||nowweight=='')){
			$.alert(parent.$, "体重不能为空!");
			return false
		}
		$("#saveInfo").attr("disabled","true"); 
		var url='/binShopService/saveInfo';
		var data={'customerIds':customerIds,'nowweight':nowweight};
		var reData = common_ajax.ajaxFunc(url,data);
		if(reData == "200"){
			 $.slideMsg("开始服务", parent.$);
			 parent.refresh();
			 parent.window.nodeClick("体重登记", "/binShopService?flag=1");
			
		}else{
			$.alert(parent.$, reData);
		}
	}























var today = new Date();   // 获取当前时间
	$(document).ready(function () {
		//tabs选中后查询
		//tabsSelect();
		//delweightShow();
		
	
		
		
	});
	
	
	
	
	//获取顾客信息
	function clearsj(){
		$("#customerName").textbox("clear");
		$("#customerPhone").textbox("clear");
		$("#customerHybh").textbox("clear");
	}

	

	function FormatDate (strTime) {
	    var date = new Date(strTime);
	    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
	}
	 //减重记录上一月
	 function  jfjl_syy()
	 {
		 var date=$('#month1').val();
		 $('#month1').val(getPreMonth(date));
		 var customerIds=$('#customerIds').val();
		 getDelweiRecord(customerIds,getPreMonth(date));
		
	 }
	 //减重记录下一月
	 function  jfjl_xyy()
	 {
		 var date=$('#month1').val();
		 $('#month1').val(getNextMonth(date));
		 var customerIds=$('#customerIds').val();
		 getDelweiRecord(customerIds,getNextMonth(date));
		
	 }
	//减重目标上一月
	 function  jfmb_syy()
	 {
		 var date=$('#month2').val();
		 $('#month2').val(getPreMonth1(date));
		 var customerIds=$('#customerIds').val();
		 getDelWeight(customerIds,getPreMonth1(date));
	 }
	//减重目标下一月
	 function  jfmb_xyy()
	 {
		 var date=$('#month2').val();
		 $('#month2').val(getNextMonth1(date));
		 var customerIds=$('#customerIds').val();
		 getDelWeight(customerIds,getNextMonth1(date));
	 }
	 /*获取减肥记录
	  * 
	  */
	function  getDelweiRecord(customerIds,date)
	{	
		var url='/binShopService/getDelweiRecord';
		var data={"customerIds":customerIds,"date":date}
		var reData = common_ajax.ajaxFunc(url,data,"json");
//				if(reData!="")
//				{
			delweightShow(reData);
//				}
		
	}
	function   getDelWeight(customerIds,date)
	{	
		  var url="/binShopService/getDelweight";
		  var data={"customerIds":customerIds,"date":date};
		  var reData = common_ajax.ajaxFunc(url,data,"json");
		  if(reData.msg == 200)
		  {
			  $('#jfmb_datagrid').datagrid({
					data: reData.delWeightList
    		  })
		  }else
		  {
			  $.alert(parent.$, reData.msg);
		  }
	    		 
	} 
		
	function    delweightShow(reData)
	{				
		var  bz_weight  = $('#bz_weight').textbox('getValue');//标准体重
		var  yj_weight  = $('#yj_weight').textbox('getValue');//应减斤数
		var  hj_weight  = $('#hj_weight').textbox('getValue');//已减斤数
		var  wj_weight  = parseFloat(yj_weight)-parseFloat(hj_weight);//未减斤数
					/*折线图*/
					require.config({
				            paths: {
				                echarts: 'http://echarts.baidu.com/build/dist'
				            }
				        });
				         require(
			            [
			                'echarts',
			                'echarts/chart/bar',
			                'echarts/chart/line'
			            ],
			            function (ec) {
			                var myChart = ec.init(document.getElementById('lineChart'));                
			                var option = {
							       	tooltip : {
							        trigger: 'axis'
							    },
							    legend: {
							        data:['体重','标准体重']
							    },
							    toolbox: {
							        show : true,
							        orient: 'horizontal',      				                                  
							        x: 'right',               				                                  				                                  
							        y: 'top',                  				                                 				                                   
							        color : ['#1e90ff','#22bb22','#4b0082','#d2691e'],
							        backgroundColor: 'rgba(0,0,0,0)', 
							        borderColor: '#ccc',      
							        borderWidth: 0,            
							        padding:5,               
							        showTitle: true,
							        feature : {				      
							            dataView : {
							                show : true,
							                title : '数据视图',
							                readOnly: true,
							                lang : ['数据视图', '关闭'],
							                optionToContent: function(opt) {
							                    var axisData = opt.xAxis[0].data;
							                    var series = opt.series;
							                    var table = '<table style="width:100%;text-align:center"><tbody><tr>'
							                                 + '<td>时间</td>'
							                                 + '<td>' + series[0].name + '</td>'
							                                 + '<td>' + series[1].name + '</td>'
							                                 + '</tr>';
							                    for (var i = 0, l = axisData.length; i < l; i++) {
							                        table += '<tr>'
							                                 + '<td>' + axisData[i] + '</td>'
							                                 + '<td>' + series[0].data[i] + '</td>'
							                                 + '<td>' + series[1].data[i] + '</td>'
							                                 + '</tr>';
							                    }
							                    table += '</tbody></table>';
							                    return table;
							                }
							            },
							            magicType: {
							                show : true,
							                title : {
							                    line : '动态类型切换-折线图',
							                    bar : '动态类型切换-柱形图',
							                },
							                type : ['line', 'bar']
							            },
							        }
							    },
							    calculable : true,
							    xAxis : [
							        {
							            type : 'category',
							            boundaryGap : false,
							            data : function (){
							                var list = [];
							                if(reData!=null && reData!="")
							                {
							                	for(var i=0;i<reData.length;i++)
								                {	
								                	var time=FormatDate(reData[i].date);
								                	list.push(time);
								                }
							                }else
							                {
							                	list.push(0);
							                }
							                return list;
							            }()
							        }
							    ],
							    yAxis : [
							        {
							        	min:80,
							        	max:160,
							        	splitNumber:5
							        }
							    ],
							    series : [
							        {
							            name:'体重',
							            type:'line',
							            data:function (){
							                var list = [];
							                if(reData!=null)
							                {
								                for(var i=0;i<reData.length;i++)
								                {
								                	list.push(reData[i].weight);
								                }
							                }
							                return list;
							            }()
							        },
							        {
							            name:'标准体重',
							            type:'line',
							            data:function (){
							                var list = [];
							                if(bz_weight!=null)
							                {
							                	 for (var i = 1; i <= 31; i++) {
									                	list.push(bz_weight);
									                }
							                }
							                return list;
							            }()
							        }
							    ]
			                };        
			                myChart.setOption(option); 
			                window.onresize = myChart.resize;
			            }
			        );
			        /* 饼状图*/
			    	require.config({
				            paths: {
				                echarts: 'http://echarts.baidu.com/build/dist'
				            }
				        });
				         require(
			            [
			                'echarts',
			                'echarts/chart/pie'
			            ],
			            function (ec) {
			                var myChart = ec.init(document.getElementById('pieChart'));                
			                var option = {
							    tooltip : {
							        trigger: 'item',
							        formatter: "{a} <br/>{b} : {c} ({d}%)"
							    },
							    legend: {
							        orient : 'vertical',
							        x : 'left',
							        data:['未减体重','已减体重']
							    },
							    toolbox: {
							        show : true,
							        feature : {
							            dataView : {show: true, readOnly: true, lang : ['数据视图', '关闭'],},
							            magicType : {
							                show: true, 
							                type: ['pie'],
							                option: {
							                    funnel: {
							                        x: '35%',
							                        width: '40%',
							                        funnelAlign: 'left',
							                        max: 1548
							                    }
							                }
							            }
							        }
							    },
							    calculable : true,
							    series : [
							        {
							            name:'完成比例',
							            type:'pie',
							            radius : '60%',
							            center: ['50%', '60%'],
							            data:[
							                {value:wj_weight, name:'未减体重'},
							                {value:hj_weight, name:'已减体重'}
							            ]
							        }
							    ]
			                };        
			                myChart.setOption(option);
			                window.onresize = myChart.resize;
			            }
			        );  

	}
     /*日常上一步下一步
      * 
      */
     var lifeItems=document.getElementsByClassName("lifeItem");
		var drinkWaters=document.getElementsByClassName("drinkWater");
		function lifeItemsTab(n){
			for(var i=0;i<lifeItems.length;i++){
				if(i==n){
					lifeItems[i].style.display="block";
				}else{
					lifeItems[i].style.display="none";
				}
			}
		}
		
		/*tab选中事件
		 * 
		 */	
		function  tabsSelect()
		{
			 $('#info_tabs').tabs({  
				 	border:false,
			      onSelect:function(title){ 
			    	  if(title=="日常")
			    	  {		
			    		 
			    		  var customerIds=$('#customerIds').val();
			    		  var url="/binShopService/getCusHabit";
			    		  var data={"customerIds":customerIds}
			    		  var divid="dailyLife_tab";
			    		  common_ajax.ajaxDiv(divid,url,data);
			    		  selectCombobox();
			    	  }
			          
			      }   
			 });
		}
		
		function   selectCombobox()
		{
			var snacks=$('#snacks').val();
			var fruits=$('#fruits').val();
			var greetings=$('#greetings').val();
			var drink=$('#drink').val();
			var sports=$('#sports').val();
			var astriction=$('#astriction').val();
			var mood=$('#mood').val();
			var menstrualperiod=$('#menstrualperiod').val();
			var ailment=$('#ailment').val();
			
			$("#snacks_select").combobox({
				 onLoadSuccess: function () 
				 {  comboboxSelected($("#snacks_select"),snacks);	}
			});
			$("#fruits_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#fruits_select"),fruits);	}
			})
			$("#greetings_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#greetings_select"),greetings);	}
			})
			$("#drink_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#drink_select"),drink);	}
			})
			$("#sports_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#sports_select"),sports);	}
			})
			$("#astriction_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#astriction_select"),astriction);	}
			})
			$("#mood_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#mood_select"),mood);	}
			})
			$("#menstrualperiod_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#menstrualperiod_select"),menstrualperiod);	}
			})
			$("#ailment_select").combobox({
				 onLoadSuccess: function () 
				 {	comboboxSelected($("#ailment_select"),ailment);	}
			})
		}
		function  	comboboxSelected(com,value)
		{
			  var val = com.combobox('getData'); 
	  		  for(var i=0;i<val.length;i++)
	  		  {		
	  			  if(val[i].value==value)
	  			  {
	  				com.combobox('select', val[i].value); 
	  			  }
	  		  }
		}			
					
		var prodata;
		var reData1;
		function suxing() {
			$('#services_part').window('open');
			var customerIds=$('#customerIds').val();
			$('#suxing_datagrid').datagrid({});
			var rows = $('#suxing_datagrid').datagrid('getRows');
			if(rows.length == 0){
				/*
				 * 获取服务人员
				 * */
				var  sevUserUrl='/binShopService/getServicesUser';
				var  sevUserReData = common_ajax.ajaxFunc(sevUserUrl,null,"json");
				/*
				 * 获取动态表头（顾客拥有产品）
				 * */
				var url='/binShopService/getPartProduct';
				var data={"customerIds":customerIds};
				var reData = common_ajax.ajaxFunc(url,data,"json");
				prodata=reData;
				var columnsAll = new Array();
				columnsAll.push({field:'choice',checkbox:true});
				columnsAll.push({field:'positionIds',title:'服务部位Ids',hidden:'true'});
				columnsAll.push({field:'position',title:'服务部位',width:100,align:'center'});
				columnsAll.push({field:'userids',title:'服务人员',width:100,align:'center',
					formatter:function(value,row){
						return row.name;
					},
					editor:{
						type:'combobox',
						options:{
							valueField:'userids',
							textField:'name',
							method:'get',
							data:sevUserReData
						}
					}
				});
				for(var i=0;i<reData.length;i++)
				{	
					columnsAll.push({field:reData[i].ids,title:reData[i].name,hidden:'true'});
					columnsAll.push({field:'use_'+reData[i].ids,title:reData[i].name+'使用次数',width:100,align:'center',
						editor:{type:'numberspinner',options:{precision:1,increment:0.1,min:0.1
								}}});
					columnsAll.push({field:'surplus_'+reData[i].ids,title:reData[i].name+'剩余次数',width:100,align:'center'});
				}
				columnsAll.push({field:'remarks',title:'备注',width:50,align:'center'});
				/*
				 * 获取表格内容
				 * */
				var url1="/binShopService/getPartInfo";
				var data1={"customerIds":customerIds};
				reData1 = common_ajax.ajaxFunc(url1,data1,"json");
				$('#suxing_datagrid').datagrid({
					  iconCls: 'icon-edit',
					  singleSelect:true,  
					  fitColumns:true,
					  toolbar: '#tb',
					  data:reData1,
					  onClickRow: function(index){
						  
						  if (editIndex != index){
								if (endEditing()){
									$('#suxing_datagrid').datagrid('selectRow', index)
											.datagrid('beginEdit', index);
									editIndex = index;
								} else {
									$('#suxing_datagrid').datagrid('selectRow', editIndex);
								}
							}
						  initRowSpan(reData, reData1);
					  },
					  onEndEdit: function(){
						  initRowSpan(reData, reData1);
					  },
					  columns:[columnsAll],
					  onLoadSuccess: function (){
						  initRowSpan(reData, reData1);
					  },
					  selectOnCheck:$(this).is(':checked'),
					  checkOnSelect:$(this).is(':checked')
				});
			}
		}
		
		//初始化合并行样式
		function initRowSpan(reData, reData1){
			for(var i=0;i<reData.length;i++){
				  $('#suxing_datagrid').datagrid('mergeCells',{
						index: 0,
						field: 'surplus_'+reData[i].ids,
						rowspan: reData1.length
					});
			  }
		}
		/*点击确定修改使用经验
		 * 
		 */
		function useNum(){	
			endEditing();
			var checkRows=$('#suxing_datagrid').datagrid('getChecked');
			for(var j=0;j<prodata.length;j++){	
				var sum=0;
				for(var i=0;i<checkRows.length;i++){
					var a=checkRows[i]['use_'+prodata[j].ids];
					sum+=parseFloat(a);
				}
				var row0=$('#suxing_datagrid').datagrid('getRows')[0];
				var ss=parseFloat(row0['surplus_'+prodata[j].ids])-sum;
				row0['surplus_'+prodata[j].ids]=ss.toFixed(1);
				var a=prodata[j].ids;
				$('#suxing_datagrid').datagrid('updateRow', {
	                index: 0,
	                row: {
	                	surplus_a:ss
	                }
				})
			}
			initRowSpan(prodata, reData1);
			
			//表格数据拼接到form
			$("#partPro").html("");
			for(var j=0;j<prodata.length;j++)
			{
				
				if(checkRows.length>0)
				{	
					var surplus = checkRows[0]['surplus_'+prodata[j].ids];
					$("#partPro").append("<input type='hidden' name='customerProductList["+j+"].productID' value='"+prodata[j].ids+"'/>");
					$("#partPro").append("<input type='hidden' name='customerProductList["+j+"].totalExperience' value='"+surplus+"'/>");
					$('#isShaPing').val("1");
					
					
					for(var i=0;i<checkRows.length;i++)
					{
						var productIds = prodata[j].ids;
						var positionIds = checkRows[i].positionIds;
						var userids = checkRows[i].userids;
						var use = checkRows[i]['use_'+productIds];
						$("#partPro").append("<input type='hidden' name='serviceShapingList["+(checkRows.length*j+i)+"].partIds' value='"+positionIds+"'/>");
						$("#partPro").append("<input type='hidden' name='serviceShapingList["+(checkRows.length*j+i)+"].userIds' value='"+userids+"'/>");
						$("#partPro").append("<input type='hidden' name='serviceShapingList["+(checkRows.length*j+i)+"].productIds' value='"+productIds+"'/>");
						$("#partPro").append("<input type='hidden' name='serviceShapingList["+(checkRows.length*j+i)+"].usage' value='"+use+"'/>");
					}
				}
			}
		}
		
		
		//点击尺寸
		function chicun(days){
			$('#size').window('open');
			if(days==-1){
				$("#partSize_div11").html("亲，第一次量尺寸哦！");
			}else{
				$("#partSize_div11").html("亲，您已经"+days+"天没量尺寸了");
			}
			
			/*var customerIds=$('#customerIds').val();
			$('#posSize_datagrid').datagrid({});
			var rows = $('#posSize_datagrid').datagrid('getRows');
			if(rows.length == 0){	
				//查出尺寸
				var url="/binShopService/getPartSizeInfo";
				var data={"customerIds":customerIds};
				var reData = common_ajax.ajaxFunc(url,data,"json");
				
				
				$('#posSize_datagrid').datagrid({
					  iconCls: 'icon-edit',
					  singleSelect:true,  
					  fitColumns:true,
					  columns:[[
					            {field:'positionIds',hidden:'true'},
					            {field:'position',title:'测量部位',width:70,align:'center'},
					            {field:'positionSize',title:'测量尺寸(cm)',width:70,align:'center',editor:{type:'numberspinner',options:{precision:1,increment:0.1,min:0}}}
					            ]],
					   data:reData,
					   onClickRow:onClickRow
				})
				
				
			}*/
			
		}
		//尺寸关闭时
		/*function partSizeClose()
		{
			endEditing1();
			var changeRows=$('#posSize_datagrid').datagrid('getChanges');
			if(changeRows.length>0)
			{	
				$.messager.confirm('请确认', '确认修改测量尺寸？', function(o)
						{
							if(o)
							{
								$("#partSize").html("");
								var rows = $('#posSize_datagrid').datagrid('getRows');
								for(var i=0;i<rows.length;i++){
									var positionIds = rows[i].positionIds;
									var position = rows[i].position;
									var positionSize = rows[i].positionSize;
									$("#partSize").append("<input type='hidden' name='servicePartSizeList["+i+"].partIds' value='"+positionIds+"'/>");
									$("#partSize").append("<input type='hidden' name='servicePartSizeList["+i+"].size' value='"+positionSize+"'/>");
								}
							}
						});
			}
		}*/
		
	
		
		
		
		var editIndex = undefined;
		function endEditing(){
			if (editIndex == undefined){return true}
			if ($('#suxing_datagrid').datagrid('validateRow', editIndex)){
				var ed = $('#suxing_datagrid').datagrid('getEditor', {index:editIndex,field:'userids'});
				var name = $(ed.target).combobox('getText');
				$('#suxing_datagrid').datagrid('getRows')[editIndex]['name'] = name;
				$('#suxing_datagrid').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
			
		}
		var editIndex1 = undefined;
		function endEditing1(){
			if (editIndex1 == undefined){return true}
			if ($('#posSize_datagrid').datagrid('validateRow', editIndex1)){
				$('#posSize_datagrid').datagrid('endEdit', editIndex1);
				editIndex1 = undefined;  
				return true;
			} else {
				return false;
			}
		}
		function onClickRow(index){
			
			if (editIndex1 != index){
				if (endEditing1()){
					$('#posSize_datagrid').datagrid('selectRow', index);
					$('#posSize_datagrid').datagrid('beginEdit', index);
					editIndex1 = index;
				} else {
					$('#posSize_datagrid').datagrid('selectRow', editIndex1);
				}
			}
			
		}
		
		/* 获取上一个月
         *
         * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
         */
        function getPreMonth(date) {
            var arr = date.split('-');
            var year = arr[0]; //获取当前日期的年份
            var month = arr[1]; //获取当前日期的月份
            var year2 = year;
            var month2 = parseInt(month) - 1;
            if (month2 == 0) {//如果是1月份，则取上一年的12月份
                year2 = parseInt(year2) - 1;
                month2 = 12;
            }
            if (month2 < 10) {
                month2 = '0' + month2;//月份填补成2位。
            }
            var t2 = year2 + '-' + month2 ;
            return t2;
        }
        /* 获取上一个月
         *
         * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
         */
        function getPreMonth1(date) {
            var arr = date.split('-');
            var year = arr[0]; //获取当前日期的年份
            var month = arr[1]; //获取当前日期的月份
            var day = arr[2]; //获取当前日期的日
            var days = new Date(year, month, 0);
            days = days.getDate(); //获取当前日期中月的天数
            var year2 = year;
            var month2 = parseInt(month) - 1;
            if (month2 == 0) {//如果是1月份，则取上一年的12月份
                year2 = parseInt(year2) - 1;
                month2 = 12;
            }
            var day2 = day;
            var days2 = new Date(year2, month2, 0);
            days2 = days2.getDate();
            if (day2 > days2) {//如果原来日期大于上一月的日期，则取当月的最大日期。比如3月的30日，在2月中没有30
                day2 = days2;
            }
            if (month2 < 10) {
                month2 = '0' + month2;//月份填补成2位。
            }
            var t2 = year2 + '-' + month2 + '-' + day2;
            return t2;
        }
        /* 获取下一个月
         *
         * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
         */
        function getNextMonth(date) {
            var arr = date.split('-');
            var year = arr[0]; //获取当前日期的年份
            var month = arr[1]; //获取当前日期的月份
            var year2 = year;
            var month2 = parseInt(month) + 1;
            if (month2 == 13) {//如果是1月份，则取上一年的12月份
                year2 = parseInt(year2) +  1;
                month2 = 1;
            }
            if (month2 < 10) {
                month2 = '0' + month2;//月份填补成2位。
            }
            var t2 = year2 + '-' + month2 ;
            return t2;
        }
        /* 获取下一个月
         *
         * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
         */
        function getNextMonth1(date) {
            var arr = date.split('-');
            var year = arr[0]; //获取当前日期的年份
            var month = arr[1]; //获取当前日期的月份
    	    var day = arr[2]; //获取当前日期的日
            var days = new Date(year, month, 0);
            days = days.getDate(); //获取当前日期中月的天数
            var year2 = year;
            var month2 = parseInt(month) + 1;
            if (month2 == 13) {//如果是1月份，则取上一年的12月份
                year2 = parseInt(year2) +  1;
                month2 = 1;
            }
        	var day2 = day;
            var days2 = new Date(year2, month2, 0);
            days2 = days2.getDate();
            if (day2 > days2) {//如果原来日期大于上一月的日期，则取当月的最大日期。比如3月的30日，在2月中没有30
                day2 = days2;
            }
            if (month2 < 10) {
                month2 = '0' + month2;//月份填补成2位。
            }
            var t2 = year2 + '-' + month2 + '-' + day2;//+ '-' + day2
            return t2;
        }
        
        
    		